/*
 * GraphicsFrame.java
 *
 * Created on Apr 16, 2011, 12:30:58 AM
 */
package LCPrinterInstaller;

import java.io.*;


/**
 *
 * @author bantch01
 */
public class GraphicsFrame extends javax.swing.JFrame {
//    private GraphicsPanel gpanel;

    /** Creates new form GraphicsFrameNew */
    public GraphicsFrame() {
        initComponents();
        this.setResizable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        norseButton = new javax.swing.JButton();
        academicPanel = new javax.swing.JPanel();
        academicLabel = new javax.swing.JLabel();
        library1 = new javax.swing.JCheckBox();
        library2 = new javax.swing.JCheckBox();
        library3 = new javax.swing.JCheckBox();
        koren = new javax.swing.JCheckBox();
        main = new javax.swing.JCheckBox();
        olin = new javax.swing.JCheckBox();
        valders = new javax.swing.JCheckBox();
        cfa = new javax.swing.JCheckBox();
        jensen = new javax.swing.JCheckBox();
        dormsPanel = new javax.swing.JPanel();
        dormsLabel = new javax.swing.JLabel();
        ylvi = new javax.swing.JCheckBox();
        olson = new javax.swing.JCheckBox();
        miller = new javax.swing.JCheckBox();
        larsen = new javax.swing.JCheckBox();
        farwell = new javax.swing.JCheckBox();
        diesith = new javax.swing.JCheckBox();
        brandt = new javax.swing.JCheckBox();
        installButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        norseButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/luther.gif"))); // NOI18N

        academicLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        academicLabel.setText("Academic Buildings");

        library1.setText("Library - Single");

        library2.setText("Library - Double");

        library3.setText("Library - Color");

        koren.setText("Koren");

        main.setText("Main");

        olin.setText("Olin");
        olin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                olinActionPerformed(evt);
            }
        });

        valders.setText("Valders");

        cfa.setText("CFA");

        jensen.setText("Jensen");

        org.jdesktop.layout.GroupLayout academicPanelLayout = new org.jdesktop.layout.GroupLayout(academicPanel);
        academicPanel.setLayout(academicPanelLayout);
        academicPanelLayout.setHorizontalGroup(
            academicPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(academicPanelLayout.createSequentialGroup()
                .add(academicPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jensen)
                    .add(cfa)
                    .add(library3)
                    .add(academicPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, library1)
                        .add(library2))
                    .add(koren)
                    .add(main)
                    .add(olin)
                    .add(valders))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(academicLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
        );
        academicPanelLayout.setVerticalGroup(
            academicPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(academicPanelLayout.createSequentialGroup()
                .add(academicLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(academicPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(academicPanelLayout.createSequentialGroup()
                        .add(46, 46, 46)
                        .add(library3))
                    .add(academicPanelLayout.createSequentialGroup()
                        .add(library1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(library2)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(koren)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(main)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(olin)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(valders)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cfa)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jensen)
                .add(53, 53, 53))
        );

        dormsLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        dormsLabel.setText("Dorms");

        ylvi.setText("Ylvi");

        olson.setText("Olson");

        miller.setText("Miller");

        larsen.setText("Larsen");

        farwell.setText("Farwell");

        diesith.setText("Diesith");
        diesith.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diesithActionPerformed(evt);
            }
        });

        brandt.setText("Brandt");

        org.jdesktop.layout.GroupLayout dormsPanelLayout = new org.jdesktop.layout.GroupLayout(dormsPanel);
        dormsPanel.setLayout(dormsPanelLayout);
        dormsPanelLayout.setHorizontalGroup(
            dormsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(dormsPanelLayout.createSequentialGroup()
                .add(dormsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(ylvi)
                    .add(olson)
                    .add(miller)
                    .add(larsen)
                    .add(brandt)
                    .add(farwell)
                    .add(diesith))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(dormsLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
        );
        dormsPanelLayout.setVerticalGroup(
            dormsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(dormsPanelLayout.createSequentialGroup()
                .add(dormsLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(brandt)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(diesith)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(farwell)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(larsen)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(miller)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(olson)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ylvi))
        );

        installButton.setText("Install");
        installButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                installButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(47, 47, 47)
                .add(norseButton))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(academicPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(27, 27, 27)
                .add(dormsPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(layout.createSequentialGroup()
                .add(51, 51, 51)
                .add(installButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 185, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(15, 15, 15)
                .add(norseButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 172, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(dormsPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(academicPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 232, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(installButton)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void diesithActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diesithActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_diesithActionPerformed

    private void olinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_olinActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_olinActionPerformed

    private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed
        // TODO add your handling code here:
        printerInstaller installer = new printerInstaller();
	installer.install();
        
    }//GEN-LAST:event_installButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GraphicsFrame().setVisible(true);
            }
        });
    }
    
    
    public class printerInstaller
	{
		private String[] printers = new String[16];//Must be updated with the number of printers
		String pQue; //ex. va_240_a
		String pName; //ex. Valders (the name of the printer as you'll see it in the printer list)
		String pLoc; //ex. Valders Lab Room 240
		String pDriver; //ex. (whatever location)
		String pUrl; //ex. lpd://printspooler.luther.edu/va_240_a
		
		public void install()
		{
			if (brandt.isSelected()) {printers[0] = "brandt";}
			if (diesith.isSelected()) {printers[1] = "diesith";}
			if (farwell.isSelected()) {printers[2] = "farwell";}
			if (larsen.isSelected()) {printers[3] = "larsen";}
			if (miller.isSelected()) {printers[4] = "miller";}
			if (olson.isSelected()) {printers[5] = "olson";}
			if (ylvi.isSelected()) {printers[6] = "ylvi";}
			if (library1.isSelected()) {printers[7] = "library1";}
			if (library2.isSelected()) {printers[8] = "library2";}
			if (library3.isSelected()) {printers[9] = "library3";}
			if (koren.isSelected()) {printers[10] = "koren";}
			if (main.isSelected()) {printers[11] = "main";}
			if (olin.isSelected()) {printers[12] = "olin";}
			if (valders.isSelected()) {printers[13] = "valders";}	
			if (jensen.isSelected()) {printers[14] = "jensen";}	
			if (cfa.isSelected()) {printers[15] = "cfa";}				

			int mycase = 0;
				
			for (String i:printers)
			{
				mycase = mycase + 1;
				if (i == null) 
				{}else
				{
					switch (mycase) {
						case 1: {
							pQue = "br_225_a";
							pName = "Brandt";
							pLoc = "Second Floor Study Lounge";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/br_225_a";} break;
						case 2:{
							pQue = "to_bl_a";
							pName = "Diesith";
							pLoc = "Main (4.5th) Floor Study Lounge";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/to_bl_a";} break;
						case 3:{
							pQue = "fw_sl_a";
							pName = "Farwell";
							pLoc = "Farwell Study Lounge";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/fw_sl_a";} break;
						case 4:{
							pQue = "la_134_a";
							pName = "Larsen";
							pLoc = "Larsen Lab Room 134";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/la_134_a";} break;
						case 5:{
							pQue = "ml_bl_a";
							pName = "Miller";
							pLoc = "Main (4.5th) Floor Study Lounge";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/ml_bl_a";} break;
						case 6:{
							pQue = "os_320_a";
							pName = "Olson";
							pLoc = "Olson Study Lounge";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/os_320_a";} break;
						case 7:{
							pQue = "yl_sl_a";
							pName = "Ylvi";
							pLoc = "Ylvi Study Lounge";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/yl_sl_a";} break;
						case 8:{
							pQue = "pl_2nd_b";
							pName = "Library - Single Sided";
							pLoc = "Library - Lab Area";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/pl_2nd_b";} break;
						case 9:{
							pQue = "pl_2nd_a";
							pName = "Library - Double Sided";
							pLoc = "Library - Lab Area";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/pl_2nd_a";} break;
						case 10:{
							pQue = "pl_2nd_cc";
							pName = "Library - Color";
							pLoc = "Library - Lab Area";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/pl_2nd_cc";} break;
						case 11:{
							pQue = "ko_121_a";
							pName = "Koren";
							pLoc = "Koren Lab Room 121";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/ko_121_a";} break;
						case 12:{
							pQue = "ma_ml_al";
							pName = "Main";
							pLoc = "Main - Language Learning Center";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/ma_ml_al";} break;
						case 13:{
							pQue = "ol_202_a";
							pName = "Olin";
							pLoc = "Olin Lab Room 202";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/ol_202_a";} break;
						case 14:{
							pQue = "va_240_a";
							pName = "Valders";
							pLoc = "Valders Lab Room 240";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/va_240_a";} break;
						case 15:{
							pQue = "jn_124_a";
							pName = "Jensen";
							pLoc = "Jensen Media Lab";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/jn_124_a";} break;
						case 16:{
							pQue = "ca_118_a";
							pName = "CFA";
							pLoc = "CFA Computer Lab 118";
							pDriver = "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd";
							pUrl = "lpd://printspooler.luther.edu/ca_118_a";} break;
						}


					//Mac Installer
					if ("Mac".equals(OSValidator.main()))
					{
						String[] myarray = {"lpadmin", "-p", pQue, "-D", pName, "-L", pLoc, "-P", pDriver, "-v", pUrl, "-E" ,"-o", "printer-is-shared=false"};

						try
						{
							Runtime rt = Runtime.getRuntime();
							Process proc = rt.exec(myarray);
							BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
							while(br.ready())
							{
								System.out.println(br.readLine());
							}
						} catch (IOException ex) {
							  ex.printStackTrace();
						}	
					}

					//Windows Installer
					if ("Windows".equals(OSValidator.main()))
					{
							
					}
				}
			}																						
		}		
	}
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel academicLabel;
    private javax.swing.JPanel academicPanel;
    private javax.swing.JCheckBox brandt;
    private javax.swing.JCheckBox cfa;
    private javax.swing.JCheckBox diesith;
    private javax.swing.JLabel dormsLabel;
    private javax.swing.JPanel dormsPanel;
    private javax.swing.JCheckBox farwell;
    private javax.swing.JButton installButton;
    private javax.swing.JCheckBox jensen;
    private javax.swing.JCheckBox koren;
    private javax.swing.JCheckBox larsen;
    private javax.swing.JCheckBox library1;
    private javax.swing.JCheckBox library2;
    private javax.swing.JCheckBox library3;
    private javax.swing.JCheckBox main;
    private javax.swing.JCheckBox miller;
    private javax.swing.JButton norseButton;
    private javax.swing.JCheckBox olin;
    private javax.swing.JCheckBox olson;
    private javax.swing.JCheckBox valders;
    private javax.swing.JCheckBox ylvi;
    // End of variables declaration//GEN-END:variables
}
